package com.wuchengdong.web.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

import java.util.List;
import java.util.Map;

@Mapper
public interface DashboardMapper {

    // 1. 今日预约数、订单数、营业额
    @Select("""
        SELECT
            (SELECT COUNT(*) FROM appointment WHERE DATE(appointment_time) = CURDATE()) AS todayAppointments,
            (SELECT COUNT(*) FROM orders WHERE DATE(created_at) = CURDATE()) AS todayOrders,
            (SELECT IFNULL(SUM(amount), 0) FROM payment WHERE DATE(created_at) = CURDATE() AND status = 'success') AS todayRevenue
        """)
    Map<String, Object> getTodayStats();

    // 2. 最近7天预约趋势（返回字段：date, appointments）
    @Select("""
        SELECT
            DATE(appointment_time) AS date,
            COUNT(*) AS appointments
        FROM appointment
        WHERE appointment_time >= CURDATE() - INTERVAL 6 DAY
        GROUP BY DATE(appointment_time)
        ORDER BY DATE(appointment_time)
        """)
    List<Map<String, Object>> getAppointmentTrend();

    // 3. 最近7天订单数（返回字段：date, orders）
    @Select("""
        SELECT
            DATE(created_at) AS date,
            COUNT(*) AS orders
        FROM orders
        WHERE created_at >= CURDATE() - INTERVAL 6 DAY
        GROUP BY DATE(created_at)
        ORDER BY DATE(created_at)
        """)
    List<Map<String, Object>> getOrderTrend();
}
